//
//  CompleteConmmandInfoViewController.m
//  ForestPack
//
//  Created by jimmy on 2018/7/9.
//  Copyright © 2018年 郑洲. All rights reserved.
//

/// 完善需求信息 控制器

#import "CompleteConmmandInfoViewController.h"
#import "Masonry.h"

@interface CompleteConmmandInfoViewController ()<UITableViewDelegate, UITableViewDataSource>
{
    NSInteger _index;
}

@property (nonatomic,strong)  UITableView  * tableView;
@property (nonatomic,copy)       NSString  * value;

@end

@implementation CompleteConmmandInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _index = -1;
    [self setTitle:@"完善需求信息"];
    [self setTableViewUI];
    
}

-(void)submitBtnClick
{
    if (_needType) {
        _needType(self.value);
    }
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)setTableViewUI
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 74;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 53;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    UIImageView *leftImageV = [[UIImageView alloc] init];
    leftImageV.image = [UIImage imageNamed:@"红色矩形"];
    [view addSubview:leftImageV];
    [leftImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view).offset(15);
        make.left.equalTo(view.mas_left).offset(1);
        make.width.equalTo(@1.2);
        make.height.equalTo(@23);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"您需要的服务类型是什么？";
    titleLabel.textColor = FONTCOLOR_BLACK;
    titleLabel.font = Kfont(18);
    titleLabel.textAlignment = NSTextAlignmentLeft;
    [view addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view);
        make.left.equalTo(leftImageV.mas_left).offset(13);
        make.right.equalTo(view.mas_right).offset(-10);
        make.height.equalTo(@53);
    }];
    
    UILabel *lineLabel = [[UILabel alloc] init];
    lineLabel.backgroundColor = RGB_COLOR(220,220,220);
    [view addSubview:lineLabel];
    [lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom);
        make.left.equalTo(view.mas_left);
        make.right.equalTo(view.mas_right);
        make.height.equalTo(@1);
    }];
    
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 164;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    UIButton *submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    submitBtn.layer.masksToBounds = YES;
    submitBtn.layer.cornerRadius = 22;
    submitBtn.backgroundColor = RGB_COLOR(237,34,59);
    [submitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    submitBtn.titleLabel.font = Kfont(16);
    [submitBtn addTarget:self action:@selector(submitBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_top).offset(60);
        make.left.equalTo(view.mas_left).offset(13);
        make.right.equalTo(view.mas_right).offset(-13);
        make.height.equalTo(@44);
    }];
    
    return view;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CompleteConmmandInfoCell * cell = [tableView dequeueReusableCellWithIdentifier:@"CompleteConmmandInfoCell"];
    if (cell == nil) {
        cell = [CompleteConmmandInfoCell cellWithTableView:tableView andIndexPath:indexPath];
    }
    if (indexPath.row == 0) {
        cell.label.text = @"彩印设计" ;
    }else if (indexPath.row == 1){
        cell.label.text = @"水印设计" ;
    }else if (indexPath.row ==2){
        cell.label.text = @"数码设计" ;
    }else{
        cell.label.text = @"结构设计" ;
    }
    
    if (indexPath.row == _index) {
        cell.label.layer.borderColor = RGB_COLOR(237,34,59).CGColor;
        cell.label.textColor = RGB_COLOR(237,34,59);
    }else{
        cell.label.layer.borderColor = RGB_COLOR(220,220,220).CGColor;
        cell.label.textColor = FONTCOLOR_BLACK ;
    }
    
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    
    _index = indexPath.row;
    
    if (indexPath.row == 0) {
        self.value = @"彩印设计" ;
    }else if (indexPath.row == 1){
        self.value = @"水印设计" ;
    }else if (indexPath.row ==2){
        self.value = @"数码设计" ;
    }else{
        self.value = @"结构设计" ;
    }
    
    [self.tableView reloadData];
}


@end


@interface CompleteConmmandInfoCell()



@end

@implementation CompleteConmmandInfoCell

+ (CompleteConmmandInfoCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"CompleteConmmandInfoCell";
    CompleteConmmandInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[CompleteConmmandInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

-(void)createSubView
{
    self.label = [[UILabel alloc] init];
    self.label.textAlignment = NSTextAlignmentCenter;
    self.label.layer.masksToBounds = YES;
    self.label.layer.cornerRadius = 22;
    self.label.layer.borderWidth = 0.5;
    self.label.font = Kfont(16);
    [self addSubview:self.label];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(15);
        make.left.equalTo(self.mas_left).offset(13);
        make.right.equalTo(self.mas_right).offset(-13);
        make.height.equalTo(@44);
    }];
    
}

@end




